package com.iris.live.services.data.repositories.impl;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.iris.live.services.data.repositories.GroupCustomerRepository;
import com.iris.live.services.models.PageData;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author: luojie
 * date: 2017/12/18 14:39
 */
@Repository
@Transactional
public class GroupCustomerRepositoryImpl extends BaseRepository implements GroupCustomerRepository {

    @Override
    public PageData findAllByPermit(Map map) {
        String sql = " select a.* from 团内客户表 a where a.许可 = :permit ";
        Map params = Maps.newHashMap();
        params.put("permit", map.get("permit"));
        if (!Strings.isNullOrEmpty(map.get("企业名称").toString())) {
            sql += " AND a.企业名称 like :companyName ";
            params.put("companyName", "%" + map.get("企业名称") + "%");
        }
        if (!Strings.isNullOrEmpty(map.get("社会信用代码").toString())) {
            sql += " AND a.社会信用代码 like :socialCreditCode ";
            params.put("socialCreditCode", "%" + map.get("社会信用代码") + "%");
        }
        if (!Strings.isNullOrEmpty(map.get("纳税人识别号").toString())) {
            sql += " AND a.纳税人识别号 like :taxpayerID ";
            params.put("taxpayerID", "%" + map.get("纳税人识别号") + "%");
        }
        int pageIndex = Integer.valueOf(map.get("pageIndex").toString());
        int pageSize = Integer.valueOf(map.get("pageSize").toString());
        PageData<Map<String, Object>> pageData = this.getPage(sql, params, pageSize, pageIndex);
        return pageData;
    }
}